//
//  EaseBubbleView+ChatBusinessCard.m
//  SISSAPP
//
//  Created by 优房网 on 2017/6/27.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "EaseBubbleView+ChatBusinessCard.h"


static char _userNameLabel_;
static char _phoneLabel_;
static char _userPhoneLabel_;

@implementation EaseBubbleView (ChatBusinessCard)

#pragma mark - public
- (void)setupBusinessCardBubbleView{
    
    // 昵称
    UILabel *userNameLabel = [[UILabel alloc] init];
    userNameLabel.font = [UIFont systemFontOfSize:17.0f];
    userNameLabel.textColor = COLOR(0x334A60);
//    userNameLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [self.backgroundImageView addSubview:userNameLabel];
    self.userNameLabel = userNameLabel;
    
    UILabel *phoneLabel = [[UILabel alloc] init];
    phoneLabel.font = [UIFont systemFontOfSize:15.0f];
    phoneLabel.textColor = [UIColor lightGrayColor];
    phoneLabel.text = @"电话：";
//    phoneLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [self.backgroundImageView addSubview:phoneLabel];
    self.phoneTitleLabel = phoneLabel;
    
    // 手机号
    UILabel *userPhoneLabel = [[UILabel alloc] init];
    userPhoneLabel.font = [UIFont systemFontOfSize:15.0f];
    userPhoneLabel.textColor = MAIN_COLOR;
//    userPhoneLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [self.backgroundImageView addSubview:userPhoneLabel];
    self.userPhoneLabel = userPhoneLabel;
    
    [self _setupBusinessCardConstraints];
    
}

- (void)_setupBusinessCardConstraints{

    CGFloat offset = 8.0;
    [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backgroundImageView).offset(2 * offset);
        make.left.equalTo(self.backgroundImageView).offset(2 * offset);
    }];
    
    [self.phoneTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userNameLabel);
        make.top.equalTo(self.userNameLabel.mas_bottom).offset(10);
    }];

    [self.userPhoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.phoneTitleLabel.mas_right);
        make.centerY.equalTo(self.phoneTitleLabel);
    }];
}

- (void)updateBusinessCardMargin:(UIEdgeInsets)margin {
    if (_margin.top == margin.top && _margin.bottom == margin.bottom && _margin.left == margin.left && _margin.right == margin.right) {
        return;
    }
    _margin = margin;
    
//    [self removeConstraints:self.marginConstraints];
    [self _setupBusinessCardConstraints];
}

#pragma mark - getter and setter
- (void)setUserNameLabel:(UILabel *)userNameLabel {
    objc_setAssociatedObject(self, &_userNameLabel_, userNameLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (UILabel *)userNameLabel {
    return objc_getAssociatedObject(self, &_userNameLabel_);
}

- (void)setPhoneTitleLabel:(UILabel *)phoneTitleLabel {
    objc_setAssociatedObject(self, &_phoneLabel_, phoneTitleLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (UILabel *)phoneTitleLabel {
    return objc_getAssociatedObject(self, &_phoneLabel_);
}

- (void)setUserPhoneLabel:(UILabel *)userPhoneLabel {
    objc_setAssociatedObject(self, &_userPhoneLabel_, userPhoneLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (UILabel *)userPhoneLabel {
    return objc_getAssociatedObject(self, &_userPhoneLabel_);
}

@end
